home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / PC Card Manager / CIncludes / Math64.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-13  |  7.5 KB  |  268 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Math64.h
  3.  
  4.      Contains:    64-bit integer math Interfaces.
  5.  
  6.      Version:    System 8
  7.  
  8.      DRI:        Kenton Hanson
  9.  
  10.      Copyright:    © 1984-1996 by Apple Computer, Inc.
  11.                  All rights reserved.
  12.  
  13.      Warning:    *** APPLE INTERNAL USE ONLY ***
  14.                  This file may contain unreleased API's
  15.  
  16.      BuildInfo:    Built by:            SuperMario Build Daemon
  17.                  With Interfacer:    2.0d11   (PowerPC native)
  18.                  From:                Math64.i
  19.                      Revision:        5
  20.                      Dated:            3/18/96
  21.                      Last change by:    ngk
  22.                      Last comment:    Change conditional now that Mth64 is available for System 7
  23.  
  24.      Bugs:        Report bugs to Radar component “System Interfaces”, “Latest”
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __MATH64__
  29. #define __MATH64__
  30.  
  31. #ifndef __TYPES__
  32. #include <Types.h>
  33. #endif
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if PRAGMA_IMPORT_SUPPORTED
  40. #pragma import on
  41. #endif
  42.  
  43. #if PRAGMA_ALIGN_SUPPORTED
  44. #pragma options align=mac68k
  45. #endif
  46.  
  47. /*
  48. --------------------------------------------------------------------------------
  49.                 These routines are intended to provide C software support for
  50.                 64 bit integer types.  Their behavior should mimic anticipated
  51.                 64 bit hardware. This implementation should replace use of the
  52.                 "wide" type found in PowerPC.
  53.  
  54.     The following routines are available for performing math on 64-bit integers:
  55.     
  56.     S64Max
  57.                 Returns the largest representable SInt64.
  58.     S64Min
  59.                 Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  60.                 (absolute value) of this number is not representable in an SInt64.
  61.                 That means that S64Negate(S64Min) is not representable (in fact,
  62.                 it returns S64Min).
  63.     S64Add
  64.                 Adds two integers, producing an integer result.  If an overflow
  65.                 occurs the result is congruent mod (2^64) as if the operands and
  66.                 result were unsigned.  No overflow is signaled.
  67.     
  68.     S64Subtract
  69.                 Subtracts two integers, producing an integer result.  If an overflow
  70.                 occurs the result is congruent mod (2^64) as if the operands and
  71.                 result were unsigned.  No overflow is signaled.
  72.  
  73.     S64Negate
  74.                 Returns the additive inverse of a signed number (i.e. it returns
  75.                 0 - the number).  S64Negate (S64Min) is not representable (in fact,
  76.                 it returns S64Min).
  77.     
  78.     S64Absolute
  79.                 Returns the absolute value of the number (i.e. the number if
  80.                 it is positive, or 0 - the number if it is negative).
  81.                 See S64Negate above.
  82.                 
  83.     S64Multiply
  84.                 Multiplies two signed numbers, producing a signed result.  Overflow
  85.                 is ignored and the low-order part of the product is returned.  The
  86.                 sign of the result is not guaranteed to be correct if the magnitude
  87.                 of the product is not representable.
  88.     S64Divide
  89.                 Divides dividend by divisor, returning the quotient.  The remainder
  90.                 is returned in *remainder if remainder (the pointer) is non-NULL.
  91.                 The sign of the remainder is the same as the sign of the dividend
  92.                 (i.e. it takes the absolute values of the operands, does the division,
  93.                 then fixes the sign of the quotient and remainder).  If the divisor
  94.                 is zero, then S64Max() will be returned (or S64Min() if the dividend
  95.                 is negative), and the remainder will be the dividend; no error is
  96.                 reported.
  97.     
  98.     S64Set
  99.                 Given an SInt32, returns an SInt64 with the same value.  Use this
  100.                 routine instead of coding 64-bit constants (at least when the
  101.                 constant will fit in an SInt32).
  102.     
  103.     S64SetU
  104.                 Given a UInt32, returns a SInt64 with the same value.
  105.     
  106.     S64Compare
  107.                 Given two signed numbers, left and right, returns an
  108.                 SInt32 that compares with zero the same way left compares with
  109.                 right.  If you wanted to perform a comparison on 64-bit integers
  110.                 of the form:
  111.                         operand_1 <operation> operand_2
  112.                 then you could use an expression of the form:
  113.                         xxxS64Compare(operand_1,operand_2) <operation> 0
  114.                 to test for the same condition.
  115.                 
  116.                 CAUTION: DO NOT depend on the exact value returned by this routine.
  117.                 Only the sign (i.e. positive, zero, or negative) of the result is
  118.                 guaranteed.
  119.  
  120.     S64And, S64Or, S64Eor and S64Not
  121.     
  122.                 Return Boolean (1 or 0) depending on the outcome of the logical
  123.                 operation.
  124.  
  125.     S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  126.     
  127.                 Return the Bitwise result.
  128.                 
  129.     S64ShiftRight and S64ShiftLeft
  130.     
  131.                 The lower 7 bits of the shift argument determines the amount of 
  132.                 shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  133.                 is a logical shift.
  134.  
  135.     SInt64ToLongDouble
  136.                 
  137.                 Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  138.                 long doubles, thus, the binary -> decimal conversion routines
  139.                 in fp.h can be used to achieve SInt64 -> long double -> decimal
  140.                 conversions.
  141.                 
  142.     LongDoubleToSInt64
  143.     
  144.                 Converts a long double to a SInt64.  Any decimal string that fits
  145.                 into a SInt64 can be converted exactly into a long double, using the
  146.                 conversion routines found in fp.h.  Then this routine can be used
  147.                 to complete the conversion to SInt64.
  148.                 
  149.                 
  150.     
  151.     The corresponding UInt64 routines are also included.
  152.     
  153. --------------------------------------------------------------------------------
  154. */
  155. #if FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE
  156. #if GENERATINGPOWERPC
  157. extern SInt64 S64Max(void );
  158.  
  159. extern SInt64 S64Min(void );
  160.  
  161. extern SInt64 S64Add(SInt64 x, SInt64 y);
  162.  
  163. extern SInt64 S64Subtract(SInt64 left, SInt64 right);
  164.  
  165. extern SInt64 S64Negate(SInt64 value);
  166.  
  167. extern SInt64 S64Absolute(SInt64 value);
  168.  
  169. extern SInt64 S64Multiply(SInt64 xparam, SInt64 yparam);
  170.  
  171. extern SInt64 S64Divide(SInt64 dividend, SInt64 divisor, SInt64 *remainder);
  172.  
  173. extern SInt64 S64Set(SInt32 value);
  174.  
  175. extern SInt64 S64SetU(UInt32 value);
  176.  
  177. extern SInt32 S32Set(SInt64 value);
  178.  
  179. extern long S64Compare(SInt64 left, SInt64 right);
  180.  
  181. extern Boolean S64And(SInt64 left, SInt64 right);
  182.  
  183. extern Boolean S64Or(SInt64 left, SInt64 right);
  184.  
  185. extern Boolean S64Eor(SInt64 left, SInt64 right);
  186.  
  187. extern Boolean S64Not(SInt64 value);
  188.  
  189. extern SInt64 S64BitwiseAnd(SInt64 left, SInt64 right);
  190.  
  191. extern SInt64 S64BitwiseOr(SInt64 left, SInt64 right);
  192.  
  193. extern SInt64 S64BitwiseEor(SInt64 left, SInt64 right);
  194.  
  195. extern SInt64 S64BitwiseNot(SInt64 value);
  196.  
  197. extern SInt64 S64ShiftRight(SInt64 value, UInt32 shift);
  198.  
  199. extern SInt64 S64ShiftLeft(SInt64 value, UInt32 shift);
  200.  
  201. extern long double SInt64ToLongDouble(SInt64 value);
  202.  
  203. extern SInt64 LongDoubleToSInt64(long double value);
  204.  
  205. extern UInt64 U64Max(void );
  206.  
  207. extern UInt64 U64Add(UInt64 x, UInt64 y);
  208.  
  209. extern UInt64 U64Subtract(UInt64 left, UInt64 right);
  210.  
  211. extern UInt64 U64Multiply(UInt64 xparam, UInt64 yparam);
  212.  
  213. extern UInt64 U64Divide(UInt64 dividend, UInt64 divisor, UInt64 *remainder);
  214.  
  215. extern UInt64 U64Set(SInt32 value);
  216.  
  217. extern UInt64 U64SetU(UInt32 value);
  218.  
  219. extern UInt32 U32SetU(UInt64 value);
  220.  
  221. extern long U64Compare(UInt64 left, UInt64 right);
  222.  
  223. extern Boolean U64And(UInt64 left, UInt64 right);
  224.  
  225. extern Boolean U64Or(UInt64 left, UInt64 right);
  226.  
  227. extern Boolean U64Eor(UInt64 left, UInt64 right);
  228.  
  229. extern Boolean U64Not(UInt64 value);
  230.  
  231. extern UInt64 U64BitwiseAnd(UInt64 left, UInt64 right);
  232.  
  233. extern UInt64 U64BitwiseOr(UInt64 left, UInt64 right);
  234.  
  235. extern UInt64 U64BitwiseEor(UInt64 left, UInt64 right);
  236.  
  237. extern UInt64 U64BitwiseNot(UInt64 value);
  238.  
  239. extern UInt64 U64ShiftRight(UInt64 value, UInt32 shift);
  240.  
  241. extern UInt64 U64ShiftLeft(UInt64 value, UInt32 shift);
  242.  
  243. extern long double UInt64ToLongDouble(UInt64 value);
  244.  
  245. extern UInt64 LongDoubleToUInt64(long double value);
  246.  
  247. extern SInt64 UInt64ToSInt64(UInt64 value);
  248.  
  249. extern UInt64 SInt64ToUInt64(SInt64 value);
  250.  
  251. #endif
  252. #endif
  253.  
  254. #if PRAGMA_ALIGN_SUPPORTED
  255. #pragma options align=reset
  256. #endif
  257.  
  258. #if PRAGMA_IMPORT_SUPPORTED
  259. #pragma import off
  260. #endif
  261.  
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265.  
  266. #endif /* __MATH64__ */
  267.  
  268.